<template>
  <section>
    <div v-show="showIndexList">
      <XdoCard :bordered="false">
        <div ref="area_head">
          <XdoBreadCrumb show-icon>
            <XdoButton type="primary" class="dc-margin-right" :loading="searchLoading" @click="handleSearchSubmit">查询</XdoButton>
            <XdoButton type="warning" class="dc-margin-right" @click="handleShowSearch">查询条件</XdoButton>
          </XdoBreadCrumb>
        </div>
        <div ref="area_search" >
          <div v-show="showSearch">
            <div class="separateLine"></div>
            <EmsCusExgCurListSearch ref="listSearch"></EmsCusExgCurListSearch>
          </div>
        </div>
      </XdoCard>
      <XdoCard :bordered="false">
        <div class="action" ref="area_actions">
          <template v-for="item in actions">
            <XdoButton v-if="item.needed === true" :type="item.type" :disabled="item.disabled" :loading="item.loading" style="font-size: 12px" :class="item.key"
                    @click="item.click" :key="item.label">
              <Icon :type="item.icon" size="22" class="xdo-icon"/>{{ item.label }}</XdoButton>&nbsp;
          </template>
        </div>
      </XdoCard>
      <XdoCard :bordered="false">
        <!--@on-row-dblclick="handleRowDblClick"-->
        <XdoTable class="dc-table" @on-row-dblclick='getExgCopGNo' ref="table" :columns="gridConfig.gridColumns" :height="dynamicHeight"
                 :data="gridConfig.data" :loading="tableLoading" stripe :border="gridConfig.data.length > 0" @on-selection-change="handleSelectionChange"></XdoTable>
        <div ref="area_page">
          <XdoPage class="dc-page" :current="pageParam.page" :page-size='pageParam.limit' :total="pageParam.dataTotal" show-total show-sizer
                   @on-change="pageChange" @on-page-size-change="pageSizeChange" :page-size-opts="[15,20,30,40]"/>
        </div>
      </XdoCard>
    </div>
    <EmsCusExgCurEdit v-if="!showIndexList" @onEditBack="editBack" :editConfig="editConfig"></EmsCusExgCurEdit>
  </section>
</template>
<script>
  import EmsCusExgCurEdit from './EmsCusExgCurEdit'
  import EmsCusExgCurListSearch from './EmsCusExgCurListSearch'
  import { jx_bill_testUri } from '@/api'
  import { getColumnsByConfig  } from '@/common'
  import { columnsConfig,columns  } from './emsCusExgCurColumns'
  import { commonProcess } from '@/view/jx_bill_test-common'
  import { editStatus } from '@/view/jx_bill_test-common/constant'

  export default {
    name: 'EmsCusExgCurList'+'-PAGE',
    components: {
      EmsCusExgCurListSearch,
      EmsCusExgCurEdit,

    },
    props: {
      emsNo: { type: Object},
    },
    mixins: [ columns, commonProcess ],
    data() {
      return {
        formItem:{
          copGNo:'',
          gNo:'',
          codeTS:'',
          gname:'',
          gmodel:'',
          unit:'',
          unit2:''
        },
        num:'',
        showIndexList: true,
        showEdit: false,
        actions: [
        ],
      }
    },
    mounted() {
      this.gridConfig.gridColumns = getColumnsByConfig(this.totalColumns, columnsConfig)
      this.refreshDynamicHeight()
      // this.getList()
    },
    methods: {
      //row 当前行数据
      getExgCopGNo(row){
        this.formItem.gNo=row.gno
        this.formItem.codeTS=row.codeTS
        this.formItem.gName=row.gname
        this.formItem.gModel=row.gmodel
        this.formItem.unit=row.unit
        this.formItem.unit1=row.unit1
        this.formItem.unit2=row.unit2
        this.formItem.copGNo=row.copGNo
        //向父组件传值
        this.$emit('showFormItem',this.formItem)
      },
      getList() {
        this.$refs.listSearch.searchParams.emsNo=this.emsNo
        this.tableLoading = true
        this.$nextTick(() => {
          let params = Object.assign({}, this.getSearchParams())
          // 配置其他参数
          this.$http.post(jx_bill_testUri.exgCurrManageUrl.emsCusExgCur.list, params, {params: this.pageParam}).then(res => {
            if (res.data.success) {
              this.tableLoading = false
              this.gridConfig.data = res.data.data
              this.pageParam.dataTotal = res.data.total
            }
          }, () => {})
        })
      },
      handleView() {
          this.editConfig.editStatus = editStatus.SHOW
          this.editConfig.editData = this.gridConfig.selectData
          this.editConfig.headId = this.gridConfig.selectData.sid
          this.showIndexList = false
      },
      editBack(val) {
        if(val){
          this.showIndexList = true
          this.gridConfig.selectRows = []
          this.getList()
        }
      },
    }
  }
</script>
<style lang="less" scoped>
</style>
